package com.lanxin.stu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanxin.stu.dto.StudentAddDTO;
import com.lanxin.stu.dto.StudentSearchDTO;
import com.lanxin.stu.entity.Classes;
import com.lanxin.stu.entity.Student;
import com.lanxin.stu.mapper.StudentMapper;
import com.lanxin.stu.mapstruct.StudentMapStruct;
import com.lanxin.stu.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanxin.stu.vo.StudentVO;
import com.lanxin.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cyh
 * @since 2025-09-17
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapStruct studentMapStruct;

    @Override
    public PageVO<StudentVO> selectStudentPage(StudentSearchDTO studentSearchDTO) {
        IPage<StudentVO> pageDTO = new Page<>(studentSearchDTO.getPage(),studentSearchDTO.getPageSize());
        IPage<StudentVO> pageVO = baseMapper.selectStudentPage(pageDTO,studentSearchDTO);
        return new PageVO<>(pageVO);
    }

    @Override
    public boolean addStudent(StudentAddDTO studentAddDTO){
        Student student =studentMapStruct.toAddEntity(studentAddDTO);
        int id = baseMapper.insert(student);
        return id > 0;
    }
}
